[][src]Crate ttf_parser

A high-level, safe, zero-allocation TrueType font parser.

Features

  • A high-level API, for people who doesn't know how TrueType works internally. Basically, no direct access to font tables.
  • Zero heap allocations.
  • Zero unsafe.
  • Zero dependencies.
  • no_std/WASM compatible.
  • Fast.
  • Stateless. All parsing methods are immutable methods.
  • Simple and maintainable code (no magic numbers).

Safety

  • The library must not panic. Any panic considered as a critical bug and should be reported.
  • The library forbids the unsafe code.
  • No heap allocations, so crash due to OOM is not possible.
  • All recursive methods have a depth limit.
  • Technically, should use less than 64KiB of stack in worst case scenario.
  • Most of arithmetic operations are checked.
  • Most of numeric casts are checked.

Error handling

ttf-parser is designed to parse well-formed fonts, so it does not have an Error enum. It doesn't mean that it will crash or panic on malformed fonts, only that the error handling will boil down to Option::None. So you will not get a detailed cause of an error. By doing so we can simplify an API quite a lot since otherwise, we will have to use Result<Option<T>, Error>.

Modules

kern

A kerning table implementation.

name_id

A list of name ID's.

Structs

Class

A value of Class Definition Table.

Font

A font data handle.

GlyphId

A type-safe wrapper for glyph ID.

LineMetrics

A line metrics.

Name

A Name Record.

Names

An iterator over font's names.

RasterGlyphImage

A glyph's raster image.

Rect

A rectangle.

ScriptMetrics

A script metrics used by subscript and superscript.

Tag

A 4-byte tag.

Variation

A font variation value.

VariationAxes

An iterator over variation axes.

VariationAxis

A variation axis.

Enums

GlyphClass

A glyph class.

PlatformId

A platform ID.

RasterImageFormat

A glyph raster image format.

TableName

A table name.

Weight

A font weight.

Width

A font width.

Traits

OutlineBuilder

A trait for glyph outline construction.

Functions

fonts_in_collection

Returns the number of fonts stored in a TrueType font collection.